#include "EnemyFish.h"
#include "PlayerController.h"
#include "GameStateManager.h"
#include "GameStateEnum.h"

void EnemyFish :: Update(float deltaTime)
{

	if (GameStateManager::GetGameState() == Playing)
	{
		float toPlayerX = player->pos.x - pos.x;
		float toPlayerY = player->pos.y - pos.y;
		float distToPlayer = sqrt((toPlayerX * toPlayerX) + (toPlayerY * toPlayerY));
		if (distToPlayer < minDistanceToAttack)
		{
			player->Die();
		}
		else
		{
			//moveToPosition
			sf::Vector2f moveToPos = sf::Vector2f(standardPos.x, standardPos.y + 50.0f * sin(myTimer.getElapsedTime().asSeconds()));
			pos = Lerp(pos, moveToPos, 0.5f);

		}
	}
	else if (GameStateManager::GetGameState() == PlayingFullyGrown)
	{
		//moveToPosition
		sf::Vector2f moveToPos = sf::Vector2f(standardPos.x - 300, standardPos.y);
		pos = Lerp(pos, moveToPos, deltaTime);

		float toSpotX = moveToPos.x - pos.x;
		float toSpotY = moveToPos.y - pos.y;
		float distToSpot = sqrt((toSpotX * toSpotX) + (toSpotY * toSpotY));

		if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left))
		{
			pos = pos;

		}

		if (distToSpot < 50.0f)
		{
			GameStateManager::SetGameState(PlayingAteAllFish);
			player->isVisable = false;
			isVisable = false;
		}
			
	}
	
}